VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsDocumento"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

Public codigo As String
Public codNodo As String
Public codTipoDocumento As String
Public codGestion As String
Public numero As String
Public fecha As String
Public concepto As String
Public total As Double
Public observaciones As String

Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(doc)
    orset.setTablas Array(doc)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
Public Sub consulta()
    orset.consulta
End Sub
Public Sub consultaTipoDoc(codTipoDoc As String)
    orset.consulta Array(doc_tdo_id & "=" & codTipoDoc)
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(doc_id & "='" & codig & "'")
    orset.CierraRec
End Sub

Public Sub asignaVenta(traCod As String)
    orset.sInsertGral Array(trd_tra_id, trd_doc_id), _
                      Array(traCod, Me.codigo), _
                      Array(trd), False, False
                      
End Sub
Public Sub asignaTercero(terCod As String, fecha As String, monto As String, cobrado As String)
    orset.sInsertGral Array(cms_doc_id, cms_com_id, cms_fecha, cms_monto, cms_cobrado), _
                      Array(Me.codigo, terCod, fecha, monto, cobrado), _
                      Array(cms), False, False
End Sub

Public Sub borrarVentas()
    Dim sventas As ClsSQL
    Set sventas = New ClsSQL
    sventas.setCampos Array(trd_tra_id)
    sventas.setTablas Array(trd)
    sventas.setCondiciones Array(trd_doc_id & "='" & Me.codigo & "'")
    orset.sDeleteGral Array(tra), _
                      Array(tra_id & " IN (" & sventas.sSelect & ")")
    orset.sDeleteGral Array(trd), _
                      Array(trd_doc_id & "='" & Me.codigo & "'")
End Sub
Public Sub borrarComisiones()
    orset.sDeleteGral Array(cms), _
                      Array(cms_doc_id & "='" & Me.codigo & "'")
End Sub

Public Function comisionesCobradas() As Boolean
    comisionesCobradas = False
    orset.consultaGral Array(cms_cobrado), Array(cms), _
                       Array(cms_doc_id & "='" & Me.codigo & "'", _
                             cms_cobrado & "=" & formatBoolBD("1")), _
                       , False
    If orset.numRegistros > 0 Then
        comisionesCobradas = True
    End If
End Function

'metodos abm
Public Sub Nuevo(newNodId As String, newTdoId As String, newGesId As String, newNumero As String, newFecha As String, newConcepto As String, newTotal As String, newObservaciones As String)
    orset.sInsert Array("", newNodId, newTdoId, newGesId, newNumero, newFecha, newConcepto, newTotal, newObservaciones)
End Sub
Public Sub Modificar(codig As String, newNodId As String, newTdoId As String, newGesId As String, newNumero As String, newFecha As String, newConcepto As String, newTotal As String, newObservaciones As String)
    orset.sUpdate Array(codig, newNodId, newTdoId, newGesId, newNumero, newFecha, newConcepto, newTotal, newObservaciones)
End Sub
Public Sub Borrar(codig As String)
    Me.consultaDatos codig
    Me.borrarComisiones
    Me.borrarVentas
    orset.sDelete Array(doc_id & "='" & codig & "'")
End Sub
Private Sub Reload_members()
    With orset
        codigo = .getDato(doc_id)
        codNodo = .getDato(doc_nod_id)
        codTipoDocumento = .getDato(doc_tdo_id)
        codGestion = .getDato(doc_ges_id)
        numero = .getDato(doc_numero)
        fecha = .getDato(doc_fecha)
        concepto = .getDato(doc_concepto)
        total = .getDato(doc_total)
        observaciones = .getDato(doc_observaciones)
    End With
    RaiseEvent DataChanged
End Sub
Private Sub orset_DataChanged()
    Reload_members
End Sub
